Fixing write to support non-blocking.