Code refactoring. Created new middleware to ensure authentication.