Fix to properly check for 'undefined' and assign default values