Logout method and refatoring.