tree filtering code cleanup