refactoring of login.function.php