Splitted main.js to client.js and main.js, added event handling