From Motor to Trajectory Plan: A feedback loop between unfolding and segmentation to improve writing order recovery