A little bug fix with handling of a cursor in #foreach