Cleaning up javascript and websocket code