additional code cleanup and refactoring
grammar now responds to grammar-selector changes