Fix bug in foreach item loop