add better grouping, add tests