Refactored to use pywrap.