Generic tree walker implementation.