refactored functions in login.js again