Yes, we are so lucky that Sondheim loves puzzles as much as he loves writing for the musical theatre. Because the weaving and use of these motifs is very puzzle like.
You may already know this, but you can read a more in depth exploration of the music in Sondheim's Broadway Musicals by Stephen Banfield. There is another book that covers some of the same territory but I loaned it to a friend years ago and am blanking on the name! Perhaps someone else here will know what I am thinking about. A third book I also enjoyed was How Sondheim Found His Sound. The author catalogs Sondheim's entire musical collection (meaning things he listened to that other people wrote) and explores how it influenced Sondheim's composing.