Made the gcode render code much cleaner and easier to understand (and fixed bugs).