Refactor grammar to make testing possible