Fixed bugs in Query error messages, better test coverage