flush writer properly