Extruder running into print at end while returning to home

I need a end G-code to rase the Z axis before homing at the end of a print. The extruder tip is hitting the print on way to home position. I have a G-code cheat sheet, and have tried a few different ones with no help. I understand Astroprint does not recognize all G-codes? Thanks for any help in advance.

JD

AstroPrint simply relays the GCODE to your printer. It might be that the printer doesn’t understand it. Which printer is it?

Here is my end code…
.
It turns on fans,retracts some filament, shuts down heaters, moves the head up a bit,
let’s things cool for a minute then homes and shuts down fans

M106 S255
G91
G1 Z20.0 E-5.0 F1800
G90
M104 S0
M140 S0
G1 X0 Y0 F2000
G4 S60
G28
M106 S0

My printer is a Geeetech Prusa I3 M201. Astroprint was running fine with my other custom slicer setups. I want to see what the “best” default on astroprint would do? The print comes out looking so much better than any of my custom setups. Then the Z axis started doing this gouging of the prints on the way to home position. I guess it just depends on where the print ends and how far over the print the Z axis has to travel on the way home?? I want the Z axis to pause, lift and/or slow down on the way home. Thanks JD

Thanks Darren I’ll give your End Code a try.