Add buffer feature and flush function