Move buffer building out of the event loop.