Refactoring for python3