Moved websocket code around to enable GUI to work better.