Move some logic into a helper function and expand the commentary.