Fixed login bug & refactoring