Refactored logic of amalgamating random-effects terms with the same grouping factor.

Also replaced {} by [] in two more places.