more dynamic casts in writeTerm
merged to head and more changes to Term identificaton
merged to head