Tested and Refactored Login