Fixing a stack overflow