refactoring client.js