Added save data function (needs to be refactored)