Refactored the main generators writing script. This fixes #6