Yep, switching back to the original code resolves the problem. All the other variables are the same, so I can safely say that the problem lies in the gcode.
I haven't seen the brackets, so let me get back to you on that. The brackets are exactly at the moment I suspect the printer crashes/gets stuck. The G1 command to raise the nozzle works, but then nothing happens.