This version works. Small tweaks based on Max’s comments.