(Btw, you don't need to use the `max` operation I suggested before. It's just the last column.

And you can also avoid the `mask`ing, but I think that's likely to obfuscate the implementation.)