move walk function out of tree code