added buffer flush