fix write to db