Further cleanup and error catching/checking.
Started integration of websockets