Fix connect() related issues

The patch fixes two issues:

1. Set the connecting flag to be false in the schema constructor
2. Register the connected handler before the connect() is called.