 In the third example, when I arrived John had cooked, John had cooked is the past perfect tense. This has the structure, subject, here, John, plus had, plus past participle, here, cooked. Past perfect is used to express the past in the past. In other words, an action that happened before another past action. When I arrived, John had cooked. I arrived in the past, and I want to say what happened before that past time. So I have to use the past perfect. The fourth example sentence, when I arrived, John had been cooking, this is using past perfect continuous tense. John had been cooking. This has the structure, subject, John, auxiliary verb, had, another auxiliary verb, been, and then the verb plus ing. The past perfect continuous tense is used to express the duration or continuity of a longer action in the past before another past action. As we can see here, when I arrived John had been cooking, the cooking had continued for a period of time before I arrived. It doesn't express whether cooking is still continuing or completed. So let's have a look at the four sentences together again. When I arrived, John cooked. I arrived first, then John cooked. When I arrived, John was cooking. The cooking was actually in progress at the time I arrived. When I arrived, John had cooked. The cooking had finished before I arrived. And when I arrived, John had been cooking. It expresses a longer action that had been happening up until the time I arrived.