added interval averaging to distance functions