Though a few cases of Ebola in the U.S. and Europe have sparked panic that the deadly virus is spreading far and wide, a closer look at the outbreak in West Africa tells a slightly different story. The epidemic, which the World Health Organization reports has claimed at least 4,877 lives, largely in West Africa, has so far been mainly confined to three countries: Guinea, Sierra Leone and Liberia. But why have others like Guinea-Bissau, Mali and Côte d’Ivoire — which all share at least one border with a badly afflicted country — so far managed to avoid any cases of the virus?

“Part of it is still luck of the draw, due to movement of people and the relatively porous nature of borders,” says Aboubacry Tall, West Africa Regional Director for Oxfam. And the threat seemingly posed by open borders has led to the affected countries gradually sealing themselves off to prevent Ebola from being passed on to neighbors. When the first cases were confirmed in March by Guinea’s Ministry of Health, Senegal decided to close its southern border with the country. As the outbreak spread to Sierra Leone and Liberia, more border closures followed: Sierra Leone shut its borders on June 11 and Liberia did the same on July 27, with the exception of a few major entry points (such as the main airport) where screening centers would be set up.

CDC

Greg Rose, a health advisor at the British Red Cross, says that while border controls may have had “a small effect” on the situation in West Africa, a key difference “was that that other countries had been forewarned,” which allowed them to “set up systems to prevent further infections.” Moreover, Tall says that “in neighboring countries like Côte d’Ivoire, Senegal and Mali, the health systems were in a slightly better shape.” In comparison, the three most-affected countries already had overburdened health care infrastructure before the Ebola outbreak. Sierra Leone and Liberia had not yet fully recovered from the damaging effects of long civil wars — Sierra Leone had two doctors per 100,000 people and Liberia had only one, whereas Mali had eight and Côte d’Ivoire had 14. (The U.S. has 242.) With a lack of staff and resources, Tall says, “Ebola came in and rapidly overwhelmed the health systems” in the three countries, which have now collectively seen more than 9,900 cases of the virus.

Tall adds that two key elements in containing the spread in neighboring countries are community mobilization and the preparedness of the public health system. He highlights the importance of “raising public awareness on Ebola” and of putting the medical system “on high alert all the way to border areas, so that anything that looks like a suspect case has a higher chance of being picked up.” The difference made by a rapid response can be seen in Senegal’s success with its one Ebola case. Despite closing its border, Senegal reported its first case on Aug. 29, after a a Guinean university student traveled by road to Dakar, the capital. He was treated and recovered, and his contacts were traced and monitored. On Oct. 17, WHO declared the outbreak in Senegal officially over, saying the “most important lesson for the world at large is this: an immediate, broad-based, and well-coordinated response can stop the Ebola virus dead in its tracks.”

Though not a bordering country, Nigeria suffered an outbreak of 20 cases — including eight deaths — after a Liberian-American man died of Ebola after arriving at the main airport in Lagos. However, the government of Africa’s most populous nation was able to successfully trace those in contact with him and has since been declared Ebola-free. Nigeria has kept its borders open to travelers from the most affected countries, but increased surveillance. Dr. Faisal Shuaib, of the country’s Ebola Emergency Operation Center, recently told TIME that “closing borders tends to reinforce panic and the notion of helplessness. When you close the legal points of entry, then you potentially drive people to use illegal passages, thus compounding the problem.”

Shuaib pointed out that closing borders has another unwelcome effect: it stifles commercial activities in countries whose economies are already struggling because of the Ebola crisis. “Access to food has become a pressing concern for many people in the three affected countries and their neighbors,” Bukar Tijani, a U.N. Food and Agriculture Organization representative, said in September. In Liberia, for example, the collapse of cross-border trade meant that the price of cassava — a food staple — jumped 150% in early August. Another immediate consequence of travel restrictions, says Tall, is that “most airlines have stopped flying to these countries, which makes it more difficult for humanitarian personnel to get in and out.”

The most effective way to contain the spread of Ebola is in “proper tracing of the epidemic, containment within communities and caring for those infected,” says Rose, the Red Cross advisor, who believes “this problem is not going to be solved by closing borders.” And though Ebola has not spread quickly beyond Guinea, Liberia and Sierra Leone, it’s clear that neighboring countries in West Africa need to remain vigilant. As Tall says, “we’re not out of the woods yet.”

Read next: Nigeria Is Ebola-Free: Here’s What They Did Right

Write to Naina Bajekal at naina.bajekal@time.com.