added debug checks.