rewritten to use PostgreSQL