Changes to mdhimClose to avoid sending messages and to return when everything is cleaned up