some fixes in terms of map

Mainly, make a intermediate function to get the keys we want. 
We seem to have the same confusion here as with addBuiltin[s].

I proposed changing the mid_ versions (because that mid_ prefix is pretty meaningless) to the non-plural versions of allocateIncompleteTentatives and resolveReferences, not changing the plural versions to the non-plural versions.