Fixed file renaming and added exception handling in case that something goes wrong during file renaming