add debug msgs and test for null return from query