Reducing loc

with open() as f, and nesting loops that only call functions.
Switched flag-set order to be more logical

Given the last bits of the program scan for the flag first, then
apply changes as determined in the sets, I decided to change the
order around from `if 1, then use 0 and 2` to
`if 0, then use 1 and 2`.
Comments