Fix possible stack overflow