Added events stuff, tests, cleaned up sockets.js.