refactor insertInOrder