This is a better approach. Avoiding bad prints and seg faults.