added additional error check