Bugfix in db.py relating to parameter binding.
Refactor for efficiency and clarity.
Merge branch 'master' into bugfix/db-params