implemented the isvalid method