refactor: grammar general refactor and improvements