Refactor authentication.