Extracted a client and wrote tests for it