Fixes a NullArgumentException but not the issue.
Need to dig deeper to understand why this code is messy.