Does removing the subfiles decrement the count?  I suspect it should, but it probably doesn't.

Would it be better to check this before the subfiles are removed in the lines above?