A bit of refactoring that shouldn't change any semantics.

In preparation for a fix to #1267.