Refactored the client. Added a test as well