somewhat major restructuring to allow the use of a threadpool - work in progress 1