Refactor: Remove deep nesting and extract methods.