Fix counting to take into account nulls