fixed check for undefined