Any way to get sequence flow in order after editing bpmn diagram

I am currently using sequence flow from elementRegistry to display bpmn diagram in a flowchart. The flowchart can be edited to add new user task. But after adding user task, the sequence flow is not in order. Is there any other way of getting all elements of the bpmn diagram in order after editing the diagram?
Any help would be appreciated. thanks.