Refactoring client and API