ISTM the exit functions should run in reverse order.