Update sp.py

minor refactoring