[MOD] XQuery: better error messages, various refactorings