-Codechange: invert the logic of 2 if-statements, reducing scoping

Also fix some minor coding-style violations.