Optimise quit logic.