changed to use instruction sequences
optimized save and restore of registers