Refactoring in smo.py