Renaming file, added more error checking