How to have a better nights sleep

When my insomnia was really bad, I used to sleep until 11pm, wake up, fall asleep again until 1am, then spend until 5am trying to get my body back into a normal sleep rhythm. I used to switch my computer on and go on the internet.