What can I say. I made a pact with the devil, and paid dearly.
Almost a whole day's worth of debugging, actually. Not again.
If this turns out to be slow we can always optimize the critical
parts (with no variable param count) later, or completely remove it.