fixed errors in minmax implementation