Normalized distance measure
Original patch not tested
Testing script