traverse tree without recursion