What you are saying is pretty much in line with what Matthew Walker is presenting as a hypothesis for the role of dreams in his book "Why we sleep". I have no training in the field, nor am I particularly well read on the topic, but I thought you might like a confirmation that this is not just an anecdote.