fix some bugs in python engine