Fix buffer sharing problem and change callback signature