Changed for loop to work correctly.