fixes to debugging sql queries