Fix insertSorted to preserve order of equal elements.