de-duplicate folder removal code with helper function