simplify with  try-with-resources
separate exceptions
use Map.entrySet() instead of keySet()
Fix count query errors when aggregates already exist
see https://issues.apache.org/jira/browse/JENA-766
add some cardinality tests
hasGroupBy is more accurate