A Theory of Dreaming