fixed broken autologin; fixed broken fallback to unencrypted connection; code refacto...