refactored cleaning script