Remodeled for PSQL use over Sqlite