Merged Ian's buffering optimization