some fixes in terms of map

Mainly, make a intermediate function to get the keys we want.