Replace the MAF and all the air intake tubing, also replace the PCV valve and its related tubing, sounds like someone really didnt know what they were doing on this car. The MAF measures the air going into the engine, if the intake tube is cracked after the MAF (as in the tube from the MAF to the engine) it wont measure that air and the car will run lean and possibly stall out, if its rattling it sounds like its also busted inside, head on over to a junk yard and get a used MAF and all the hoses for it, same with the PCV and its hoses, a good PCV should rattle when shaken, if not its plugged up but can be cleaned. The O2 sensor cannot in any way affect the MAF. Also check each and every vacuum line since they will also cause running issues, if your missing so many pieces there are probably lots of little vac lines broken or missing.
1997 Mazda 323 1.3L 5-speed (130,000km)
2006 Mazda3 1.6L 5-speed (40,150km)
1989 Ford F250 7.3L IDI non-wastegated turbo 5-speed
239,000 miles and counting, ORIGINAL CLUTCH, still going strong. (In USA, dont have it here in AT)
If I talk in this color it means I am speaking to you as a moderator, pay attention.