A year after the worst haj disaster in a generation, Saudi Arabia is issuing pilgrims with electronic bracelets and using more surveillance cameras to avoid a repeat of a crush that killed hundreds and damaged already strained ties with Iran.
The world's largest annual Muslim gathering, bringing some two million to Islam's most sacred sites in Mecca, will also be a focus of concerns about militant violence after a suicide bomber killed four soldiers in early July in the nearby city of Medina, Islam's second holiest.
Custodian of Islam's most revered places, Saudi Arabia stakes its reputation on organising haj, one of the five pillars of Islam which every able-bodied Muslim who can afford to is obliged to undertake at least once.
Its prestige was damaged by the 2015 disaster, in which Riyadh said 769 pilgrims were killed - the highest haj death toll since a crush in 1990. Counts of fatalities by countries who repatriated bodies showed that over 2,000 people may have died in the crush, more than 400 of them Iranians.
Iran, Saudi Arabia's main regional rival, blamed the disaster on organisers' incompetence. An official Saudi inquiry has yet to be published, but authorities suggested at the time some pilgrims ignored crowd control rules.
This year, efforts are being made to strengthen crowd management.
Thousands of civil servants, security personnel and medics have been conducting drills in preparation for the pilgrimage, which officially starts this week.
The kingdom says it is deploying extra staff and increasing coordination with haj missions from pilgrims' home countries to ensure worshippers comply with agreed schedules to perform various rituals. Hundreds of new surveillance cameras had been installed at the Grand Mosque.
"The scheduling programme is the most important part of the operational programme," Interior Ministry spokesman Major General Mansour Turki told Reuters.
"This is the area we have to concentrate on, to make sure pilgrims ...comply with it once they get there."
Saudi-owned newspaper Asharq al-Awsat said last month the Mecca Development Authority had set up electronic paths and gates to manage crowds heading to Jamarat, the symbolic stoning of the devil where many previous disasters have occurred.
The kingdom also is kitting pilgrims out with electronic wristbands to enable authorities to track the flow of people and get early warnings of crowd build-ups.
Relations between Shia Iran and Sunni Saudi Arabia, which back opposing sides in Syria and other conflicts, plummeted after the 2015 crush.
Riyadh then broke diplomatic ties when its Tehran embassy was stormed in January over the Saudi execution of a Shiae cleric.
Wary that some pilgrims may seek to use haj for ideological purposes, Saudi Arabia said it would not tolerate any attempt to politicise haj - remarks widely seen as referring to Iran.
Iran said in May its pilgrims would not attend, blaming Riyadh for "sabotage" and failing to guarantee their safety. Saudi Arabia blamed Iran, saying it had demanded the right to hold demonstrations that would have created chaos.
But Saudi Arabia is worried that Iranian pilgrims coming from abroad or pro-Iranian pilgrims from other countries could still exploit the gathering to spread anti-Saudi messages.