adopting code to fit all editions (cherry picked from commit 273ce4f)