write and flush after every classification.