updated version with better sampling of DM