Fix distance calculations and move region unlock to AppDelegate