Fix #369. Fix some edge cases with WAL recovery from crashes