[FIX] XQuery, FLWOR Optimizations. Closes #965