Extract buffering code to module