Generating sequences refactored