Improved residual calculation for heat flux