Refactor cache_package_use() and fix buggy code.