I went round the houses on this and settled on the approach for speed and readability. I've matched the interpretation of mdtol used in the aggregator class.