Client refactoring

The branch name is misleading, the refactoring I had in mind didn't work out. Please still merge these minor commits.