Moved store / restore outside of loop for better performance

Signed-off-by: Elliot Condon <e@elliotcondon.com>