Add crash protection.

Use  write-ahead logging.