Fixed writeKeyHelper to go inOrder