Fixed isValid method