improved monkey_patch to be able to name generated functions