First batch of changes to support py2.6+ and py3.0+