Improved buffering function