Corrected algorithm for validating pkg id