this is now more properly multi-threaded