Refactored, added tests to client