Solved psycopg2 issues and made general revisions