Fix bugs in python model so that all examples pass