Added __debug__ condition for expensive assertion.