fix stack overflow issue