fix and improve logging