Correct some errors
refactoring cleaning function