Revised for the latest Python and library versions.