improved the python script