fixed the dtw algorithm