checks for type null before deferencing it

The old code use accessed members of type before the check for null, which would result in a NullReferenceException. This change also removes the unnecessary `Func` object.