laying down functions for distance calculations