replaced loops with index Array methods