Changed use of sort to use of insert.