Fixed buffering issues with thread context change