max value index bug fix