tidy up and refactoring
split CS1 generation code into a class