Mofifying queries, fixing up error reporting