refactoring client.js into functional sections