bottleneck is number of iterations in distance calculation
integratied with multiprocessing. still need to speedup.