Refactor Generator#generate method