Formatting updates to improve readability.

It might look like a lot, but most changes involve returning early to reduce nesting.