added some checks for undef