Most of the client stuff refactored