Refactor generate and process module