improved optimization, enabled multithreading