Split up javascript logic from the index.
Moved sockets to separate file as well