Right off I can think of three ways to improve your mental function. (1) Make sure you are physically healthy and are not deficient in any nutrients. To me it is amazing how important it is to make sure I am not lacking in the B vitamins. Rest is also important. (2) Do whatever you can to put anxiety away from you. The littlest moods can interfere with high level thinking. A comfortable place to think is a very good thing to be able to access. (3) Develop a number of brain use strategies. I will list some examples. Memory increases when you find ways of 'hooking' the information you want to remember with something else that has importance to you. Memory increases if you use rhythm as you try to remember an item. The metronome speed of 60, the speed of largo movements in Baroque music, when listened to before you attempt to remember something, will aid retention. When information makes sense it is easier to remember.
Repetition helps retention. Ideas will come to you if you develop habits of creativity. Welcome every idea, whether you act on it or not, so as not to cause your creative side to shut down. When searching for new ideas try looking at something in a different way than before, upside down perhaps. Use questions to elicit ideas. Pay close attention to details for a while. Then switch and pay close attention to the large picture. Your brain is your magic wand. Throughout life you will be learning better ways to use it. May the spark of magic be with you for that end.