break out pg-specific code into pg.js