cleaned up countChunks method