cleanup logging
make thread safer