This patch does further refactoring using the new mp_raise_TypeError and mp_raise_ValueError functions.