Added a valid() function