Various fixes for Python 2.7 < .4 and Python 3