Added if conditional to fix seg fault and bus errors.