write to db working