More general implementation of delegate patching