changed a for loop to reduce method