Some refactoring of the client