A system has an irremovable failure source and a number of removable flaws. The system undergoes a sequence of trials designed to detect and remove the flaws. On each trial, the irremovable failure source may cause failure which in turn may block the detection of any flaws. If not, then each flaw in the system, independently, is detected on that trial with a certain probability and each detected flaw, independently, is removed from the system with a certain probability before the next trial. Distributions of the outcomes of the trials are obtained. Point estimates of the parameters, based on accumulated trial data, are given. Assuming that certain costs are associated with trials, optimal stopping rules and a cost-benefit analysis are given.