cleaning up threading code