After fox squirrels have collected their haul of nuts, they don't just stash them haphazardly. Instead, they sort them with the determination and delicate touch of a trick-or-treater organizing his candy loot on Halloween night, according to a new study.

Researchers from UC Berkeley found that fox squirrels sort their nuts by variety, quality and maybe even order of preference. They arrange their haul using "chunking," a strategy used by both humans and animals in which they organize information into smaller, more manageable groups. It's similar to how people use subfolders to sort information on a computer.

The study, which was published in the journal Royal Society Open Science, points out that fox squirrels collect somewhere between 3,000 to 10,000 nuts each year. Under some circumstances, the animals sort their bounty into subfolders or caches of different types of nuts.

“This is the first demonstration of chunking in a scatter-hoarding animal, and also suggests that squirrels use flexible strategies to store food depending on how they acquire food,” said study lead author, post-doctoral researcher Mikel Delgado, in a statement.

Not only does the organizing likely help them remember where they stored their favorite food, but it also hides the nuts from potential thieves, the researchers said.

“Squirrels may use chunking the same way you put away your groceries. You might put fruit on one shelf and vegetables on another. Then, when you’re looking for an onion, you only have to look in one place, not every shelf in the kitchen,” said study senior author and psychology professor Lucia Jacobs.

For the study, researchers tracked 45 male and female fox squirrels for two years as they buried almonds, pecans, hazelnuts and walnuts in various locations on the UC Berkeley campus. For part of the experiment, researchers fed nuts to squirrels then tracked them to find patterns in where they buried each type of nut.

They found that squirrels that typically foraged in a single location frequently organized their nuts by species, keeping each type separate. However, squirrels that went hunting in various locations were more likely to avoid burying their nuts where they had already left others, instead of organizing them by type.

Here's a look at the squirrels in action: