updated code for python2