fixed pgsql connection bug, some other improvements