Made code somewhat backwards compatible with python 2.7.