refactor detail::Map for memory efficiency