Fixed for loops since for each has been deprecated.