Consider adding a comment to explain what this is going to be used for. I've not read the rest of the code so I am unsure but it seems like something this long warrants a comment.