adding write to db function