Refactoring for support of py3.3