Fix bug in counting resources.