clean function improved