When you want to talk about two actions, and one action is in the past, and the other action is also in the past, but even "more past" than the first action, then the first past action is expressed with the past tense and the second past action, which happened before the first action, is expressed with the past perfect.
I sealed the envelope after I had placed the letter in it. =
I had placed the letter in the envelope before I sealed it.
Most in the past (before sealing): I had placed the letter in the envelope.
Not so far in the past (after placing): I sealed the envelope.
I was not aware that I had taken my medication twice.
Most in the past: I had taken my medication twice.
Not so far in the past (after taking): I was not aware of this.
Hope this helped.