Refactored authentication