refactor, improve logging