Complete `flush` function with test