Wrote line-sequence finding function