Refactoring and cleaning up the authentication process