Fixed SQL logic in _RemoteConnect hook, formatted code