improvements on multithreading and performance, bug fixes