fix stack overflow -> memory issue