If one would compare your brain to a computer, one could compare sleep to defragging your hard drive, process it all and sort it, archive the important stuff, and delete the unused temp files.
Your dreams are all this info of the day, and leftover stuff from previous incomplete runs, in high speed.
Say you drank orange juice, ate breakfast, took your dog out, and such. While defragging, your brain skims over all his info 10x faster than you normally think, so when it gets "scanned" or recalled, and turned into a remake, to you it gets all smooshed together in one big chunk of data, imagine when you copy a big list, and watching the copy bar shoo through all the files as it sorts them, that's what your dreams are.
But say something has been on your mind all day. That means there is a LOT of that chunk of data all over your brain, so it is gonna play a major role in your dream. IE that girl who sits 2 seats away from you in bio...
Sometimes unresolved data, like something troubling you a lot, your brain will skim over, but not archive and leave it for next time to be worked on more. These are nightmares. Like if your best friend died. That's a LOT of stuff for both your consciousness and subconsciousness to together work on. So the result is a seemingly never ending replay of this same little video in your head as your brain tries to analyze it, over and over and over...
The result is a recurring nightmare. Until both your consciousness and subconsciousness come to terms with this info.
It can take 2-3 days, or years, but it boils down to you facing it and seriously comprehending all f this, coming to terms with it if you will.