added more protections against seg faulting