Stylistic changes and minor improvements

PEP 8 prefers if and while statements without parentheses. It also prefers using the default truthiness of empty strings versus querying the length (although in some cases it's more clear).