restructuring and mutex to stop a defect