simplify some control flow and reduce indentation, no functionality change.