Refartoring for python 3