Added some error checking

If the web socket object have not been created any attempts to call functions on it will be skipped.