Refactor logout