Prehaps to be more logical when writing scripts, you could make a brief plan on what you are going to do. Have a look at it, and rearrange your bullet points if you think it will be easier or quicker to do it in another order.
I find that helps for me. But as said above, every person has their own method.