Delete fork and add thread

We use thread in places fork for to be less expensive in memory and cpu. We fix a bug: memory leak