slight optimizations to distances