improve the performance of Jdist for replacing