A Cognitive Theory of Dreams