code review cleanup

Logic looks fine although I've not gone through that part with a fine tooth comb.

Changes are mostly superficial formatting.