Refactor installation of packages