Fix support for purging legacy package units and add support for purging environment units