refactoring groupByProperty