Only minor nit I would pick is that in most of the cases in the refactored code, `else` could be removed. More often than not, `else` is a code smell imho, and often you're better off separating function logic and having an early return instead of an else.