Keep a reference to the correct associated context of the reference function and use that context when calling the reference function.
This sadly required making changes to the code itself, due to the same context needing to be reused for both versions. The lookup table had to be duplicated for both versions.