Adjusting and refactoring algebra.py