Fix bug in map_keys and add imporvements