Split off the utility functions and changed the way monkey_patch works