bugfix for issue with un-balanced xquery