Updated with John's patch.