fix bug in isValid