refactor: put GetPackagesName code in a separate fn, to reduce duplicate code