Added back psycopg2 requirement.
Moved remaining SQL queries into models.
Removed psycopg2 stuff.