Fix buffer check and delete