Refactor dm