refactored the authentication and authorization mechanism