Fixing bug in sequence generation