Change sort representation to class

- changed sort representation from String to class
- modified API's accordingly
- replaced string literals with constants
- cleaned up a lot of mess 
TermVisitor is kind of deprecated. I made the toFrontEnd/toBackend changes you mentioned everywhere else.