writing savings algo