Added check for undefined values