People who have trouble sleeping find it difficult to switch off the part of the brain that makes our attention wander. So not only can they not get to sleep, they also find it more difficult to complete complex tasks during the day.
https://www.express.co.uk/news/health/425755/Can-t-sleep-Blame-a-wandering-mind