Can you please add a comment at baseline to explain what the hell it's for? (Not your fault. But boy, this code is hard to follow. Great job even figuring it out.)