For one thing, you can't clear a code by disconnecting a sensor or by disconnecting the battery....it takes a scan tool/code reader to clear the code(not all code readers can clear codes)......
It's possible you fixed the EGR problem, but since you DID NOT CLEAR THE CODE, it's still there in history....
As for the P0440, changing the cap sometimes fixes it....but once again, you still don't know if that fixed it because the code wasn't properly cleared.....
Go to places like AutoZone, who will clear them for free......then run the vehicle and if the light comes back on, have the codes read again.....
Right now, you are just a parts changer, and hoping for the best....you have done no diagnosis, which is hard to do without a scan tool and diagnostic tree....you could have replaced the EGR, that was still good, and had a wiring problem or flow problem due to blockage.....you replaced the cap, but you could have a vent/purge solenoid problem, wiring problem, pressure sensor problem, a leak anywhere in the system(line, fuel tank, canister, etc.)......
You can continually replace parts and get lucky, or go to a garage or dealership with a good rep.....then even though it is fixed, you will have to drive the vehicle to reset all the emission flags....if they don't reset, you won't pass your test....