Move client-server communication to separate js file