refactored logout process