God fucking damn it. I wasted several evenings on this one feature, trying to do it this weird-ass way, and just now managed to do it about a fucktillion times better in about 30 minutes, 6 compiler errors total including typos and tests, and 40 lines of code including blank lines. I guess you don't learn without making mistakes? Shitty mistakes that waste a lot of time?