This seems unnecessarily slow. You should probably just keep an integer count. And that allows us to remove this function.