Why has the number of engine failures decreased in F1 racing?

In the past engine failures in Formula 1 were a common sight. Nowadays they are quite rare. What are the reasons behind this?

Engine longevity was regulated by the rules beginning from the Formula 1 season 2004. Beginning that year it was specified that only a single engine could be used during any specific GP weekend. Drivers were penalised of engine changes by a drop by ten (10) places in the start grid. Before 2004 engine usage was unregulared, so teams took more risks with them - engine failures were much more common. Starting from season 2005 the limitation was extended from one race weekend to two.

Granted that during 2004 and 2005 seasons, for example, Kimi Räikkönen's McLaren car's Mercedes engine was still rather unreliable due high performance level. Räikkönen suffered four engine failures in 2004 and in 2005 he got three penalties due to engine changes. In the 2004 season there was a total of 20 retirements due to engine failures.

In the 2007 season F1 regulations limited engine RPM to 19 000. Before that some engines revved to over 20 000. This limitation had a significant impact on the number of engine failures. In the 2007 season there were only 5 retirements due to engine failures. In comparison, the 1997 season the number was as high as 47.

Since 2007 the RPM limit has been lowered to 15 000 RPM. The engine lifespan of the engine has been increased, as in the 2014 season the teams must make it through 19 GP weekends with a total of 19 engines.