A new explanation for why we have nightmares contradicts the conventional wisdom about sleep