Mode cleanup on the document so it actually works. Mostly.