P0171 Code (2012 Mazda3)

Hello,
2012 Mazda 3. Recently i have had a P0171 ( System Too Lean Bank 1) code thrown on my car. When pulling the reading the code is being thrown 3 times. I have reset the code and all was normal. The check engine light came on again today after a long drive, and then idling for about 5 minutes. Being that the check engine light does not come on all the time is confusing. Recently my mass airflow sensor went out, and I replaced it. Looking around a bad MAF could be the cause. Maybe it went bad? I stopped at a traffic light, the engine ran rough for maybe 1-2 seconds ( i would describe it as a little roughness just like if the AC pump turns on), and then the check engine light comes on. I have a OMBD scanner and I can clear the codes but only 2/3 p0171 codes go away, 1 stays on there. The check engine light does go off. With my scanner tool i can see the stats like electrical volatages and such for many systems if anyone has ideas of what ones to check. The car run perfect from my perspective except when this random issue happens. Thanks
 
Back