Working dm.c code from 3.0.56