Refactor and generation