There is a blip of release of neuro-peptides that give an hour of alertness right before bedtime. Believed to be a signal to begin gathering resources and secure oneself for the night. Passes after 45-60mins. Is often when people start worrying about everything they have to do the day after, worry about not going to get enough sleep etc.
So don't put too much weight on the thoughts you get right before sleeping, or when you wake up in the middle of the night. They are basically designed to produce anxiety (alertness, wakefullness).