make logging work with multithreading, cleanup