Would it make sense to refactor the count-related parts of nanvar into a separate private function?