group matrix: made code a bit clearer