added check for undefined