When preparing for a game session prepare an Adventure Outline. Don't go into super detail. Adding more detail increases the likelihood that the party will do something that wasn't predicted. Try and make the pieces (encounters, NPCs, Traps, and random monsters) of the outline independent. Modular encounter elements planed out in advance make it much easier to adjust the adventure and adapt to the adventurers choices. Realize that the events in the outline can be taken in any order. Keep this in mind when working on the individual parts.
Provide for multiple paths that lead to the same destination. If the PCs get off track have a note or idea what might get the party back on track. Is is possible that they might run into an NPC that might do this? Write down a name and small description for the possibility. Could they find a document, hear a rumor, or find a clue? If it is prewritten then write it out in a manner that it could be placed anywhere on the fly.