minor changes, including adding semicolons after variables assigned to functions. also moved a couple of things into an outer scope which didnt need to be recomputed each call.
fixing shared side-effects for scan.
fixing spacing.
Merge pull request #1 from cwharris/minor-updates

Reduces work in scan.