Refactored client and added tests