Refactoring to Python 2.7