I agree with the stamina improving longer runs. If you can run 7k then that helps when to try to run a harder 5k because you know you can survive it, it's no-where near your long run.
Speed helps of course 400m injections of pace each km once a week would help. But, the most important thing is determination
I started off around 41m 5k and remember July when I was so excited about beating 40m I don't try really to speed up or run a fast 5k but I'm down to 31m 5k's now. It just happens naturally when you keep practising.