Made some minor changes to the order of exit-testing code.