Refactor the scripts generate.py and coverage.py