Improve modularity of grammar module code