Fixed flush function