Refactoring and Auto-login bug fixed