Main code for implementation of residual reduction algorithm (RRA)