Fixed distance calculation and added offset calculation (stochastic run away is now fixed)