rewriting with threads