Merge "Refactor and improve logging."