Refactor clients and add integration tests