I correct a bug in the memoization and implemented a check for available
nonterminals