Added buffer logic