fix empty buffer problem