Better multithreaded implementation. No exdplicit checks for race conditions.