Adding missing comma and curly
Slight spacing fixup
Misc formatting corrections, eliminating switch-in-for antipattern, other simplifications
Slight code cleanup, made a switch-case a bit clearer