Reworked a lot of stuff for threading.