improve the python part