refactor clean function