fix heap memory and threads.