Fix potential stack overflow