Fixed write to db