The container struct reduces repetition, and the helper method will simplify
future work by allowing early returns.

Differential Revision: https://phabricator.services.mozilla.com/D11272