refactor of tree walking to use single method
added tests