refactored authentication check