added a bit of threading