working preorder traversal