Refactor the grammar modules

- more user friendly names
- better grouping of functionality
- more reuse
- cleaned up unit tests