Improved handling of Python <2.7