updated code to use es6 for of