functionize save file code