Refactor generator runtime generatorWrap to reduce code duplication