refactored authentication