refactoring doLogout method.