A two-step algorithm for the dynamic reduction of flexible mechanisms