PackageManagerService: refactor for clarity/efficiency, added logging