performance optimizations for write speed and fix to recover thread exce...