Bug fixes in grouping template

Fixed bug with pre-expanded groups.