To reduce the frequency of nightmares, you can drink some coffee and go to bed. As far as I can remember, the more alert you are when trying to fall asleep, the less likely you are to have a nightmare. It also depends on how long you sleep, so sometimes you need to wake up. I follow this routine when sleeping:
1. Coffee until 50
2. Toilet
3. Sleep until 74
4. Toilet
5. Sleep from 79 to 100
6. And go to the toilet again