multithreaded code works, needs heavy refactoring #8