refactoring straighten.py