Minor refactoring on generate_sources.