objectified the postgres work and sorted out the docs