This is done in #1627.  You can either merge that or incorporate those changes here, whichever is easiest.