Documentation and refactoring of the count method