refactoring for dynamic sequence generation