Add mode=flat or mode=tree to /tags/, omit duplicates, add sum stats (issues #667, #662)