Refactored package name detection and package install process.