Added isValid() function.