convert for loops to each as per Ruby practices