refactoring clean function