Update the output function in tree to return result