Bottom-up approach to refactoring in python