refactoring code in preparation for login form