fixed typo for counter aggregates, added some null checks