Changed a slight error in the code (taking the offset from the limit).
Turns out this was the wrong approach to take. Tests show that the
latest change works as expected.