I factored out this code in the newly added 6e609e2 commit.