Rename gram_valid to gram_sd and create gram_nsd, better tests.