use early exits to reduce indentation.