Optimize some border cases for solver.
Validate pkg when changing its uid.