Good call, @cvan. Refactored in 303539f, which simplified this patch significantly.