Fixed residual bugs