Lots of 2.x/3.x compatibility changes.