beginning of cleaning up multithreaded optimisation