refactoring login and Register Handlers.