refactor from python2 to generic python