fixing handling of duplicate events in tree building code [ci skip]