modified old distance scripts