make dynamic time warping generic and fix small bugs within it