added support for $foreach.count, $foreach.index, $foreach.hasNext, $foreach.first and $foreach.last