Patch Set 4:

Rebased to current master. Testing is difficult as this is for interoperability with the command line. However, I think we will have to look into the interoperatbility issue in the next sprint anyway, and perhaps we'll come up with something there.