Cleanup of the fix, implement review feedback and match Keith's version in 4f182499fd097cdeaede49907299b6f32d30af71.