Working multi-threaded implementation