Add save and restore
Fix some small bugs
Fix some bug in close()
Add block switch to write