logout process refactored