Rebase Eric Carlson's patch.