refactored database code to use the postgres.py wrapper

also typo fix
Merge pull request #49 from BorisVerk/master

refactored database code to use the postgres.py wrapper