add flush callback. closes #16