fixed the double flash bug and the document error state bug