Uses recursive way to travel nodes.