Correcting array reference in foreach loop.