Add self-correction algorithm