Prevent NullReferenceException

The variable val was not referenced later in the function and caused a
NullReferenceException.