Replace os.rename with shutil.move to handle cases