Fix insert_sorted bug brought by refactoring (length to end useage to store the working range).