Fixed count for large collections, refactor code