First working version of the rewrite.

Bug: does not close client app.