move grouping to server side