For readability, I inlined some code that was packaged in twisty little one-time-use functions.