Update python2 branch

There were some conflicts, so I ended up fixing some things manually. No too bad.

The tests seem to run fine now, but could someone also take a look before pulling?