Fixed behaviour on failed connect, minor cleanup.