additional debugging fixes to make it more convenient to be reused

Tushka, I hope you don't care that I outsourced the db connection
debugging.