min/max implementation makes sense. Better solution would be to introduce more state variables and return them, but I wanted to avoid that.