refactored the way we check for authentication