I will be 62 soon and have suffered from insomnia my entire life...I get 3-4 hours of crappy sleep a night...I never had brain fog until a year ago...maybe it is just old age catching up with me,...
Try taking MK-677 a few hours before bed as it can wake people up when taken just before bed. I would also recommend adding in a ZMA stack with your melatonin as that can improve sleep quality and recovery in general.
I can get brain fog with many sleep products but melatonin is not one of them but it is fairly common. Are you using a slow release formula? If so I would recommend a fast one. If you aren't then maybe just lower your dose. My fav melatonin product are 21st century's quick dissolve 10mg cherry flavoured. Even my mum loves them and she is very sensitive to supplements and has had issues with other lower dosed (3-5mg) melatonin products.