Refactoring in grammar