Modified for python 2 support.