Fix a bug with the onConnect event