refactor angle and distance functions