Adapted for python2