most of the file save and restore stuff