Do not display empty groups when filtering
Speed improvements and code cleanup