Added extra check for undefined variables