Added crude check for buffer corruption