Changed the code slightly to handle different dm versions.