Major refactoring of client