Refactored login and logout code to minimize files and to redirect to the login page after the user has logged out.