refactored using array.forEach()