Fixed code to support python2 and 3