Formatting updates to improve readability.

It might look like a lot, but most changes involve returning early to reduce nesting.
It's a much more explicit comparison rather than relying on truthiness of an 0 length array.