Improve logging; fix encoding