same improvements for the python version