refactored authenticat