Update sat.py

refactoring and minor bug fixes