Please post all of your ending gcode script. It's important to understand whether you've put the printer into absolute positioning or not, and whether you're including the speed/feedrate settings (the F parameter) in your gcode commands. If not, the printer continues with whatever it was last told... which can lead to very unpredictable results.