Add missing condition and little refactor
Get distance function type from arguments