Or mashed potatoes, or mac and cheese, or chicken noodle soup.

Get the recipe.
Marcus Nilsson

Everyone has their go-to dinner or snack when they’re in a bad mood—and it turns out, the sense of comfort it provides doesn’t necessarily come from the food itself, but the memory of the person who first made it for you. If you had a positive relationship with the cook—think: your grandma’s famous mashed potatoes—you’re more likely to be drawn to that dish, according to recent findings by researchers at the University of Buffalo.

The study, published in the journal Appetite, found that these nostalgic dishes may help people feel safe in times of rejection or isolation. The researchers conducted two studies—the first threatened some participants’ sense of belonging, and found that they were drawn to comfort food after feeling they might become isolated. The second asked participants to keep a diary for two weeks, and found that they ate their preferred comfort food when feeling lonely or isolated.

All comfort food isn’t created equal, however—grilled cheese might seem like a cure-all, but you’ll only feel safe and happy after the sandwich if you remember a family member preparing it for you when you were a child. The “social connection” to the food was key for researchers in understanding how to manage vulnerability and how our social situations can influence our eating behavior.

“Because comfort food has a social function, it is especially appealing to us when we are feeling lonely or rejected,” study leader Shira Gabriel said in a statement. “The current study helps us understand why we might be eating comfort foods even when we’re dieting or not particularly hungry.”