fix problems with file renaming
clean up some things
change some things to size_t