Refactored token validation helper