Refactor 'count'