refactor the code
support showing residual point