Refactor 'generate' module