fixed #10 and #7 multithreaded alternative is working properly