Folding up fiddly bits into the algorithms