Made the exit logic more solid