Fairly large refactor and update of main generator