fix program exit from thread, improved statistics