Updated for python2 backwards compatibility.