Code P0170 indicates a lean mixture condition. Before replacing expensive components such as the Mass Airflow Sensor it is wise to check for vacuum leaks as this is the most likely culprit. Shown here is a vacuum line that goes to the Fuel Pressure Regulator of my 1.8 turbo Golf:
As you can see the vacuum line is extreme frayed and air that is not accounted for by the computer is leaking into the intake manifold causing the lean mixture condition. The line above is short and connects to the underside of the intake. It's fairly easy to remove with some needle nosed pliers. The new installed vacuum line is shown below:
Here is a picture of the old line, the pliers :-), and the new hose:
Both ends of the hose were completely frayed. A useful tip is to install a longer hose on the underside of the intake to make sure you have enough length as you route it through the maze of other hoses. You then cut the hose to the appropriate length. If you cut it first you may run into difficulties.