Fix terminal cleanup on exit by finding invisible bug.