[BUGFIX] fix variable overwrite in foreach