Extract bad_ending variable.
Simplify if...else condition.
Always ignore rmtree errors.