map_recursively function simplified