Adding second assignment code, adding residual to optimization result