updated sorting rules

changed < operator to consider base if exponents are equal
call sort after each term is added
call sort after two expressions are added