refactoring to client factory