Doing major refactoring stuff, since the threading got a little
out of hand.