the `math.max(0, ...)` can be pulled out