bug fix: bad logic for early exit