fix possible stack overflow