last commit was a mistake, it only worked because min() is actually a built-in function, as well as max()
replacing max and min with maxval and minval