optimizations to not calculate distance so much