modified for python 3