Code cleanup for Python API.