Added residual detection