fixed multithreading issues - still some problems but it runs!