Finally get working properly with updated distance measure.