Replace 'undefined' with 'null' where appropriate

See also: commit 604f767ba97e37b26b182e8b5249c68145ae4921