Sync the contribution from trtg into the Py3 version.