Fix bug in file renaming routine