Replaced for loop with indexOfObject