Minor reduction in scope of variables and minor doco.