updated for renaming files, retries and error handling