Re-organize code to be more Pythonic.
No changes in functionality.