I'm not sure whether I'm just running out of focus, but I'm really struggling to understand the complexities of this code.  Please can you add some comments and then I'll re-review?