Multi threaded implementation and heap optimization