Refactoring: Starting and ending of the sequence is configurable
Solve a bug about counting sequence elements