Added a little bit of commentary to the code, probably not a good substitute for a full explanation, but I think it'll help.