add in valid() function