Grilled cheese is more than just a chunk of dairy surrounded by gluten; it’s a national staple. The all-American dish now has its own National Grilled Cheese Day, which was celebrated Thursday. While there’s debate over how unhealthy cheese really is, the sandwich has come a long way since being a dish of Kraft slices on Wonder bread.

Like many recipes from childhood, grilled cheese has undergone a renaissance, appearing in restaurants and bars across the country. Not only has it become pub fare, it’s not uncommon to see restaurants serving sophisticated versions on the classic, like grilled brie on a baguette dipped in organic tomato basil soup. But that’s not always the best grilled cheese, according to science.

It’s All About the pH

The first step in building the perfect grilled cheese is to find the right cheese, ideally one that gets stretchy when it melts, creating that iconic stringy image when the sandwich is split in half. To achieve this quality, the cheese needs acidity in the range of pH 5.3 to 5.5, according to Reactions, a YouTube series hosted by the American Chemical Society.

Milk curdles during the cheesemaking process, removing the whey and leaving behind casein proteins, which defines the cheese’s texture. The process of curdling also causes the casein, collected into negatively charged spheres called micelles, to aggregate into a gel. Since micelles are negatively charged, these spheres would normally repel each other, but acids make the clumping process possible.

The acidity levels ultimately dictate the gooeyness of the new cheese curd. Gouda, gruyére, and manchego all fall within the range of pH 5.3 to 5.5 to create the gooey, stretchy texture.

Mild Over Sharp

If gouda isn’t available when assembling the perfect grilled cheese, stick to the rule of leaning towards mild cheese over sharp varieties. Sharper cheeses mean lower pH levels, which will have a negative effect on the calcium found inside the cheese once its heated. The cheese will release all of its oils and turn it into a curdled disaster.

There’s Bread, Too

The cheese part of a grilled cheese is what makes or breaks the sandwich. Bread preferences are entirely up to the cook, so long as the selected starch can withstand direct heat. Add a thin layer of butter or margarine to the outer slices to create that smokey taste. Expose each side of the sandwich to direct heat for two to three minutes on the grill, and voila, your sandwich is ready.

Despite new alternatives to the classic sandwich, even the best ingredients won’t take more than a few minutes to grill. The perfect grilled cheese continues to become easier, thank to scientists streamlining the cheesemaking process. Last December, researchers from the Norwegian University of Life Sciences in Ås said they designed a tool that can makes cheeses like the grilled cheese-friendly gouda at consistently higher qualities. But chemists offer a few varieties of cheese in the perfect recipe, which means chefs can work with several possible combinations.