Fixed bug on materialize distance.