To hit 40 on flat ground, you're going to need to pay particular attention to aerodynamics. Eliminate all aero drag possible, including flappy clothes, wide handlebars, wheels with large spoke counts, tires, and especially body position.
For gearing, you're going to need a bigger chainring. Rear cogs smaller than 13 teeth show increasingly large losses, so avoid going smaller and compensate by using large chainrings. A 56 or 58T ring should do it. Finally, going from 32 to 40 mph will probably require you to double your power output. I think you underestimate the magnitude of the goal, but good luck!