Updated code to use native forEach instead of for x in y