Cleanup api client

Some cleanup in the API client.

The first commit is the most interesting.