Fix usage of deprecated API
Add python2 support