When writing a longer story there is a good chance that you may notice problems with the plot, setting, and characters. If you find problems as you write it is best to wait until the next draft to fix them completely. You can adjust further segments to make it work, but you should not rewrite the current segment until later. I am defining a segment of a story as a scene. You can also use acts or chapters.
In order to remember the problems you found while writing later when you revise the draft and write the next draft all you have to do is take notes between segments. These notes can be as detailed or rough as you want, but they should tell you what you need to fix. When I write these notes I use stream of consciousness to describe what needs to be changed and/or fixed and how I can go about doing that.