fix minor bugs when handling Undefined value