fixed a bug with bestIndex