log out functionality - refactoring