WARNING - May not work after this change

Changed around the for loop to make it more elegant, hopefully it still works.