using a loop for error extraction and another loop for error subtraction