Fixed grammar (again) and added some rudimentary type checking.  It passes about half of the test cases