Fixed autoconnect.

Better naming and separation of functions.
Autoconnect now working.