Formatted source code.
minor refactoring: use inline ifs, etc