Fix strange stack overflow bug