Improved runPuppetdb function