Improve dml serialization

Related to #767