I often struggled to sleep, I would sometimes lie in bed from 2AM to 6AM, only to fall asleep after sunrise, get a couple hours and then limp into work around 10.
Now I just take Melatonin in the evening ( http://www.gwern.net/Melatonin ) and sleep somewhat normally.
EDIT: I also use the flux app, and I reduced my coffee consumption significantly, now down to zero, but melatonin had the quickest and most observable effect.