Add write check before flushing