ENH: Error checking to prevent seg fault