Fixed issue with non-websocket connections attempting to connect

Also reorganized code