fixed output residual bug