tried to make threaded, failed, then cleaned up stuff and made things more modular