fix treeing function