Worked out bugs in Postgres implementation and performed some code cleanup.