Protect against NULL when calculating counts

We had the case where there were NULLs in the member counts table, and
the counting job was not able to recover. Added some guards against NULL.