fix to residual calc
update