cleanup - refactored to simplify cleaning directories.
Merge from sibling master.