Patch Set 4:

Original implementation attempt was removed as it was the wrong approach.

I started again, with the tests. Could you please review them so that I know I'll be doing the right thing in the implementation?