code cleanup: reduce if block nesting. No functional changes.