Refactor a bit.
Trying to traverse tree just once.