isValid reimpemented using prefixes and set()