Added tree structure for top-down count