Fix not getting last sequence and update unit test.