An Alignment-Based Approach to Learning Motions from Demonstrations