added writing out valid terms