Fix stack overflow issue