refactored the grammar to be simpler