Continuing modifications to switch to postgres database.
Fixes for bugs encountered during testing.