Bug fixes and thread safety for web sockets