I'd still split this out into a separate top-level function for readability.