A few fixes over Paulo's version and many fixes to the python version.