ported changes from ndm