Fix for immediately login

It works now.

Additional comment 
IMHO, we need to make the program become more modular. The original modules are a little complicated (many dependencies, from one module to another).
Plus, please state some clear milestone/functions/features that needed. It'll really helpful to give contributors some directions.