Fix bugs in python port.