dtmmodel: bug fixes, cleanup, and tests