Cleaned up authentication logic.