added thread pool, lots of changes