moved writes to separate thread, added some blocking