pg integration and a few more changes