Update terse.py

Clean up and refactor code