I reworked this problem as my previous solution was unnecessarily complicated.  Lesson: Think more, type less.