FLT-misc-39b0.5: Distance calculations moved to own function