improved Term.php

restructured class
fixed bugs due to lack of unit testing