Code refactoring for python3.