Fast DTW reimplementation