This code's a bit funky, but I was loath to discard my refactoring, so it has a logging side-effect. :/