Minor structural changes. Better variable names and minor doco.