changed algorithm to calculate locations