Port the new modcall code from v3.

It's smaller and simpler than the previous code