Change 'add' function to be async, add calls to flush in unit tests