fix maxindex check