fix empty buffer bug