@eugenemcardle hi... sorry for the late reply, been busy on some other stuffs
a bunch of comments to improve the merge request (the overall logic looks ok, the tests are covering most of the interesting aspects, mostly code cleanup, simplification & readbility)