Refactored GroupBy with two parameters to be accept generic type