modified dist matrix calculation to perform in batches of 100,
made harmonics distance calculation ignore nan values