Improved the `pkg_to_mapping` function