updated exit logic