critical bug fix: saving while switching

rewrite saving and loading thread to avoid saving while switch document
may cover switched document issue.