Add flushing before unlocking