added write to db method