typeof null returns 'object', so protect against null values here