Fix threading issue that at best will leak memory