Refactored SDTW