Fixed the maxval 0 bug