Refactor modifies check to avoid repeating work and database lookups

Flatten out the algorithm, and only query the database once for entitlements
and once for products