save data to ram and flash