Fixing stack overflow exception during dispose