new version of improveFunction