Fixed a few bugs in the websocket rpc code, and cleaned up the code a bit too