G91 is an incremental move, it moves a measured distance from where the tool is at that moment.
G90 is an absolute move, it is a measured distance from the datum point.
Thats what was wrong with your code, you were doing incremental rotations of the A axis and then also on the X and Z, the X and Z should have been absolute moves.
Graham.