refactored code and comments added for clarity; added but not linked to phase 2's login