Refactor Distance Function.
Partial finish DTW interfaces.
Minor optimization.