update code to use insertion order