Updated motion correction code