Simplified and refactored to a pur PGQ implementation