Moved the login code into MainThread