cleanup and rename-files function