Moved null ref check to line before dereferencing