Updated grammar, refactored some code