corrected clean function