last minute (major) fix ups to get this thing working with multiple threads