improved error handing in query class