fixing stack_foreach()