fixed index out of range error when calculating distances/addresses