move array_key_exists to valid()