bug fixes and buffering code