Added grouping functions and fixed a bug when retrieving values from array with 0 index