optimization. Removing maxIndex