refactored residual plotting