Some small improvements to connect, register and receive commands from the server more reliably.