Refactor xbuffer