Implementation of save and load function