refactored sequence handling