Added checks for NULL returns by calloc