move allocation to be inside the thread