Refactored code: Remove code only used by client into client.js file