Fix stack overflow exception