refactored grammar