logic for leaving