fix for loop index/isFirst/isLast