Avoid NaN

1. Add empty check to avoid NaN. It happened when no data is coming yet, but `flush` occured. See the test.